/** * 虚拟登录 * @/views/budget/virtualLogin * 2020-9-7 * zengfx */
<template>
    <div class="virtualLogin_container" v-loading="showAllLoading"></div>
</template>

<script>
import { getRequestParams } from "@/common/js/fastInquiryFn2";
import { setCookie, delCookie } from "@/common/js/cookie";
import { setSessionStorage } from "@/common/js/storage";
import { $loginAPI, $budgetAPI } from "@/api";
export default {
    data() {
        return {
            showAllLoading: true,
            param: null
        };
    },
    methods: {
        handle_virtualLogin() {
            let param = {
                token: this.param.token
            };
            $loginAPI.getJXlogin(
                {
                    token: this.param.token || window.JXtoken,
                    loginName: this.param.loginName,
                    userName: this.param.userName,
                    userMobile: this.param.userMobile,
                    companyId: this.param.companyId,
                    timestamp: this.param.timestamp,
                    sign: this.param.sign
                },
                res => {
                    if (res.code == 0) {
                        // 保存token
                        // debugger
                        setCookie("token", res.content.token);
                        // setSessionStorage("accountInfo", res.content.userInfo);
                        window.sessionStorage.setItem(
                            "SysUserCode",
                            res.content.username
                        );
                        window.sessionStorage.setItem(
                            "userName",
                            res.content.userName
                        );
                        this.showAllLoading = false;
                        var accountInfo = {};
                        $budgetAPI.getUserInfo(
                            {},
                            res => {
                                if (res.code == 0) {
                                    accountInfo = res.content;
                                    window.sessionStorage.setItem(
                                        "accountInfo",
                                        JSON.stringify(accountInfo)
                                    );
                                    this.$router.push({ path: "/budget/home" });
                                }
                            },
                            err => {
                                console.log(err);
                            }
                        );
                        
                    } else {
                        this.showAllLoading = false;
                        this.$message.error(res.message);
                        // this.$router.push({ path: "/login" });
                    }
                },
                err => {
                    this.showAllLoading = false;
                    //  this.$router.push({ path: "/login" });
                }
            );
        }
    },
    created() {
        this.param = getRequestParams();
        // this.param = window.zjhc;
        console.log(this.param.token);
        // debugger
        this.$nextTick(() => {
            this.handle_virtualLogin();
        });
    }
};
</script>

<style lang="scss" scoped>
.virtualLogin_container {
    width: 100%;
    height: 100%;
}
</style>
